import 'package:favoritecate/core/model/category_model.dart';
import 'package:favoritecate/core/model/meal_model.dart';
import 'package:favoritecate/core/viewmodel/meal_viewmodel.dart';
import 'package:favoritecate/ui/widgets/meal_item.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:collection/collection.dart';
import '../../widgets/meal_item.dart';


class MealContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final category = ModalRoute.of(context).settings.arguments as CategoryModel;
    return Selector<FYMealViewModel,List<FYMealModel>>(
      selector: (ctx,mealVM) => mealVM.meals.where((meal) => meal.categories.contains(category.id)).toList(),//数据筛选
      shouldRebuild: (pre,next){
        //判断两个数据是否相等
        return !ListEquality().equals(pre,next);
      },
      builder: (ctx,meals,child){
        return ListView.builder(
          itemCount: meals.length,
          itemBuilder:(ctx,index){
            return FYMealItem(meals[index]);
          }
        );
      },
    );
  }
}


//class MealContent extends StatelessWidget {
//  @override
//  Widget build(BuildContext context) {
//    final category = ModalRoute.of(context).settings.arguments as CategoryModel;
//    return Consumer<FYMealViewModel>(
//      builder:  (ctx,mealVM,child){
//         print(mealVM.meals);
//         //按照类别过滤
//         final meals = mealVM.meals.where((meal) => meal.categories.contains(category.id)).toList();
//         return ListView.builder(
//           itemCount: meals.length,
//           itemBuilder: (ctx,index){
//             return ListTile(
//                 title: Text('${meals[index].title }'),
//             );
//           },
//         );
//      },
//    );
//  }
//}
